package dmp

import (
	"fmt"

	"github.com/alexeyco/simpletable"
	"github.com/mingrammer/cfmt"
)

func ShowTable(users []User) {
	table := simpletable.New()
	table.Header = &simpletable.Header{
		Cells: []*simpletable.Cell{
			{Align: simpletable.AlignCenter, Text: cfmt.Sinfo("ID")},
			{Align: simpletable.AlignCenter, Text: cfmt.Sinfo("账号")},
			{Align: simpletable.AlignCenter, Text: cfmt.Sinfo("密码")},
			{Align: simpletable.AlignCenter, Text: cfmt.Sinfo("说明")},
		},
	}
	for _, user := range users {
		r := []*simpletable.Cell{
			{Align: simpletable.AlignCenter, Text: cfmt.Ssuccess(fmt.Sprintf("%d", user.ID))},
			{Align: simpletable.AlignCenter, Text: cfmt.Ssuccess(user.Username)},
			{Align: simpletable.AlignCenter, Text: cfmt.Ssuccess(user.Password)},
			{Align: simpletable.AlignCenter, Text: cfmt.Ssuccess(user.Info)},
		}

		table.Body.Cells = append(table.Body.Cells, r)
	}
	table.Footer = &simpletable.Footer{
		Cells: []*simpletable.Cell{
			{},
			{},
			{},
			{Align: simpletable.AlignCenter, Text: cfmt.Sinfo(fmt.Sprintf("总条数: %d", len(users)))},
		},
	}
	table.SetStyle(simpletable.StyleRounded)
	table.Println()
}
